package leetcode.code189.RotateArray;

/**
 * 一次一个不行啊
 *
 * @author Max
 * @date 2021年8月13日
 * @description
 */
public class Solution1 implements IRotateArray {

	@Override
	public void rotate(int[] nums, int k) {
		for (int i = 0; i < k; i++) {
			int now = nums[0];
			int temp = 0;
			for (int j = 1; j < nums.length; j++) {
				temp = nums[j];
				nums[j] = now;
				now = temp;
			}
			nums[0] = now;
		}
	}

	public void myPrint1(int k) {
//		输入: nums = [1,2,3,4,5,6,7], k = 3
//		输出: [5,6,7,1,2,3,4]
		int[] nums = { 1, 2, 3, 4, 5, 6, 7 };
//		int k = 1;
		this.myDebug(nums, k);
	}

	public void myPrint2(int k) {
//		输入：nums = [-1,-100,3,99], k = 2
//		输出：[3,99,-1,-100]
		int[] nums = { -1, -100, 3, 99 };
//		int k = 1;
		this.myDebug(nums, k);
	}

	private void myDebug(int[] nums, int k) {
//		for (int num : nums) {
//			System.out.print(num + ",");
//		}
//		System.out.println(" ");

		IRotateArray ira = new Solution1();
		ira.rotate(nums, k);
		System.out.println(k + ">>");
		for (int num : nums) {
			System.out.print(num + ",");
		}
		System.out.println(" ");

	}

	public static void main(String[] args) {
		Solution1 so = new Solution1();
//		so.myPrint1();
//		so.myPrint2();
		so.myPrint(10);

//		int[] nums = new int[20000];
//		for (int i = 0; i < 20000; i++) {
//			nums[i] = i;
//		}
//		so.rotate(nums, 11939);
//		System.out.println(20000 + ">>");
//		int line = 0;
//		for (int num : nums) {
//			System.out.print(num + ",");
//			line++;
//			if (line == 99) {
//				System.out.print(num + ",");
//				line = 0;
//			}
//		}
//		System.out.println(" ");
	}

	private void myPrint(int k) {
		for (int i = 0; i < k; i++) {
//			this.myPrint1(i);
			this.myPrint2(i);
		}

	}

}
